package com.scrx.ymg.service.distribution;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.scrx.ymg.dao.distribution.IDistributionDao;
import com.scrx.ymg.dao.user.IUserDao;
import com.scrx.ymg.entity.Distribution;
import com.scrx.ymg.entity.User;


@Service("distributionService")
public class DistributionServiceImpl implements IDistributionService {
	
	@Autowired
	private IDistributionDao distributionDao;
	@Autowired
	private IUserDao userdao;

	@Override
	public Distribution getDistribution(int userID) {
		Distribution distribution=distributionDao.getDistribution(userID);
		User user=userdao.findById(userID);
		if(user.getReferrerId()==-1){
			distribution.setReferrerName("总店");
		}else{
		distribution.setReferrerName(userdao.findById(user.getReferrerId()).getUserName());
		}
		distribution.setDownline(userdao.getDownlineNumByUserId(userID));
		return distribution;
	}

}
